package com.example.pucha_xian.common;

import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Looper;
import android.widget.Toast;

import org.jetbrains.annotations.NotNull;

import java.io.IOException;
import java.util.Map;

import okhttp3.Call;
import okhttp3.Response;

public class DataInput {

    public static void update(Map<String, String> map, Context context, String token){
        AlertDialog.Builder builder = new AlertDialog.Builder(context);
        builder.setTitle("警告");
        builder.setCancelable(false);
        builder.setMessage("你想要更新现在标志点信息么？");
        builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                try {
//                    //数据库操作更新GPS点
//                    litepalDBOperator.updateGPSPoint(curPoint);
//                    Map<String,String> Map = Convert.object2Map(curPoint);
                    OKHttp.upload(UserUtil.updatepoint, token, map, new okhttp3.Callback(){

                        @Override
                        public void onResponse(@NotNull Call call, @NotNull Response response) {
                            Looper.prepare();
                            //提示用户更新成功
                            Toast.makeText(context, "更新成功", Toast.LENGTH_SHORT).show();
                            Looper.loop();
                            dialog.dismiss();
                        }

                        @Override
                        public void onFailure(@NotNull Call call, @NotNull IOException e) {
                            Looper.prepare();
                            Toast.makeText(context, "更新失败", Toast.LENGTH_SHORT).show();
                            Looper.loop();
                            dialog.dismiss();
                        }
                    });
                } catch (Exception e) {
                    e.printStackTrace();
                    Looper.prepare();
                    Toast.makeText(context, "更新失败", Toast.LENGTH_SHORT).show();
                    Looper.loop();
                    dialog.dismiss();
                }
                dialog.dismiss();
            }
        });
        builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
            }
        });
        builder.create().show();
    }

}
